package com.qk.management.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.qk.dto.user.UserDTO;
import com.qk.entity.User;
import com.qk.vo.user.UserVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @Author:zhengbowen
 * @Date: 2025/10/06 19:28
 * @Description:
 */
@Mapper
public interface UserMapper extends BaseMapper<User> {
    @Select("SELECT image FROM user WHERE status = 1 AND image IS NOT NULL AND image != ''")
    List<String> findValidUserAvatarUrls();

    @Select("select * from user")
    List<User> selectUserList();

    @Select("select * from user where id = #{id}")
    User selectUserById(String id);

    @Insert("INSERT INTO user(username, password, name, phone, email, gender, status, dept_id, role_id, image, remark, create_time, update_time) " +
            "VALUES(#{username}, #{password}, #{name}, #{phone}, #{email}, #{gender}, #{status}, #{deptId}, #{roleId}, #{image}, #{remark}, #{createTime}, #{updateTime})")
    void insertData(User user);

    @Select("select * from user where username = #{username}")
    User selectUserByUsername(String username);

    List<User> selectUserByRoleLabel(String roleLabel);

    List<User> selectUserByDeptId(Integer deptId);

    void deleteByIds(List<Integer> ids);

    void updateUser(User user);

    @Select("SELECT u.*, r.label as role_label FROM user u LEFT JOIN role r ON u.role_id = r.id WHERE u.username = #{username}")
    User getUserByUsername(String username);

    @Select("SELECT * FROM user WHERE username = #{username}")
    User selectByUsername(String username);

    List<UserVO> selectUsersByPage(UserDTO userDto);
}
